import {menus} from "@/assets/datas";
import { IMenuModel } from "@/typings";

export const getUserMenus = (): IMenuModel[] | null => {
    return buildMenu(0);
}

function buildMenu(parentId: any): IMenuModel[] {
    let children: Array<IMenuModel> = []
    let typeMenus = menus as IMenuModel[]
    typeMenus.forEach(menu => {
        if (menu.parentId == parentId) {
            children.push(menu)
            let buildMenus = buildMenu(menu.id);
            if (buildMenus) {
                menu.children = buildMenus
            }
        }
    })
    return children
}
